#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
class Solution
{
public:
    /**
     * @brief
     * -2^31 <= num <= 2^31 - 1
     *
     * @param num
     * @return string
     */
    string toHex(int num)
    {
        vector<int> res;
        string ans = "";
        if (num > 0)
        {
            while (num)
            {
                int t = num % 16;
                int x = (t >= 10) ? (t - 10 + 'a') : t;
                cout << "x: " << x << endl;
                res.push_back((t >= 10) ? (t - 10 + 'a') : t);
                num /= 16;
            }
            for (int i = res.size() - 1; i >= 0; i--)
            {
                cout << res[i] << endl;
                ans += char(res[i] < 10 ? res[i] + '0' : res[i]);
            }
        }
        else
        {
            uint32_t x = ~num + 1;
            cout << "x: " << x << endl;
        }

        return ans;
    }
    string baseNeg2(int N)
    {
        string ans;
        int mod, b = -2;
        if (N == 0)
            return (ans = "0");
        while (N)
        {
            mod = N % b;
            N /= b;
            if (mod < 0)
            {
                mod += 2;
                N += 1;
            }
            if (mod)
                ans = '1' + ans;
            else
                ans = '0' + ans;
        }
        return ans;
    }

    string toHex_2(int num)
    {
        if (num == 0)
        {
            return "0";
        }
        string ans = "";
        for (int s = 0, e = 4; e <= 32; s += 4, e += 4)
        {
            int decimalValue = 0;
            for (int i = s; i < e; i++)
            {
                if (num & (1 << i))
                {
                    decimalValue += (1 << (i - s));
                }
            }

            ans.push_back(decimalValue < 10 ? '0' + decimalValue : (decimalValue - 10 + 'a'));
        }
        // delete  leading zeros
        while (ans.back() == '0')
        {
            ans.pop_back();
        }
        reverse(ans.begin(), ans.end());
        return ans;
    }

    string toHex_3(int num)
    {
        string HEX = "0123456789abcdef";
        if (num == 0)
        {
            return "0";
        }
        unsigned int n = (unsigned int)num;
        string res = "";
        while (n)
        {
            res = HEX[(n & 0xf)] + res;
            n >>= 4;
        }
        return res;
    }

    string toHex_4(int num)
    {
        unsigned int uNum = num;
        switch (uNum)
        {
        case 0:
            return "0";
        case 1:
            return "1";
        case 2:
            return "2";
        case 3:
            return "3";
        case 4:
            return "4";
        case 5:
            return "5";
        case 6:
            return "6";
        case 7:
            return "7";
        case 8:
            return "8";
        case 9:
            return "9";
        case 10:
            return "a";
        case 11:
            return "b";
        case 12:
            return "c";
        case 13:
            return "d";
        case 14:
            return "e";
        case 15:
            return "f";
        }
        return toHex(uNum / 16) + toHex(uNum % 16);
    }

    string toHex_5(int num)
    {
        string s;
        if (num == 0)
        {
            return "0";
        }
        uint32_t n = num;
        while (n)
        {
            int x = n & 0xf;
            s.push_back(x < 10 ? x + '0' : (x - 10 + 'a'));
            n >>= 4;
        }
        reverse(s.begin(), s.end());
        return s;
    }
};
int main(int argc, char const *argv[])
{
    Solution s;
    // vector<long long> test = {-2147483648, -23, -1, 0, 5, 26, 2147483647};
    cout << s.toHex_5(-1) << endl;
    return 0;
}
